package net.zjitc.controller;

import net.zjitc.service.AdminService;
import net.zjitc.utils.JwtHelper;
import net.zjitc.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 毛若颖
 * @date 2024/12/20 18:55
 */
@RestController
@RequestMapping("/admin/admin")
@CrossOrigin
public class AdminController {
 @Autowired
 private AdminService adminService;

 @Autowired
 private JwtHelper jwtHelper;

 @GetMapping
 public Result AdminInfo(@RequestHeader String token){
  long adminId = jwtHelper.getUserId(token).longValue();
  Result result=adminService.getAdminInfo(adminId);
  return result;
 }
 @PostMapping("/changePassword")
 public Result update(@RequestHeader String token,@RequestBody String password){
  long adminId = jwtHelper.getUserId(token).longValue();
  Result result=adminService.updatePassword(adminId,password);
  return result;
 }
 @PostMapping("/changeAvatar")
 public Result changeAvatar(@RequestHeader String token,@RequestBody String avatar){
  long adminId = jwtHelper.getUserId(token).longValue();
  Result result=adminService.updateAvatar(adminId,avatar);
  return result;
 }

}
